<?php

class News{

	public $id;
	public $title;
	public $summary;
	public $desc;
	public $date;
	public $username;
	public $image;
	
	public static function getMaxId(){
		$query = 'SELECT Max(Id) as maxId FROM news';
		return getQueryObject($query);
	}
	
	public static function getCountRow(){
		$query = 'SELECT count(*) as countRow FROM news';
		return getQueryObject($query);
	}
	
	public static function getNews($id){
		$query = 'SELECT Id, Title, Summary, `Desc`, `Date`, Username, Image FROM news WHERE Id='.$id;
		return getQueryObject($query);
	}
	
	public static function getAll(){
		$query = 'SELECT Id, Title, Summary, `Desc`, `Date`, Username, Image FROM news ORDER BY `Date` DESC';
		return getQueryArray($query);
	}
	
	public static function getNewsLimit($from, $to){
		$query = "SELECT Id, Title, Summary, `Desc`, `Date`, Username, Image FROM news ORDER BY `Date` DESC LIMIT {$from}, {$to}";
		return getQueryArray($query);
	}
	
	public static function insertNews($title, $summary, $desc, $date, $username, $image){
		$query = "INSERT INTO news(`Title`, `Summary`, `Desc`, `Date`, `Username`, `Image`) values ('{$title}', '{$summary}', '{$desc}', '{$date}', '{$username}', '{$image}')";
		getQueryUpdate($query);
	}
	
	public static function updateNews($id, $title, $summary, $desc, $date, $username, $image){
		$query = "UPDATE news SET Title='{$title}', Summary='{$summary}', `Desc`='{$desc}', `Date`='{$date}', Username='{$username}', Image='{$image}' WHERE Id={$id}";
		getQueryUpdate($query);
	}
	
	public static function updateNewsWithoutImage($id, $title, $summary, $desc, $date, $username){
		$query = "UPDATE news SET Title='{$title}', Summary='{$summary}', `Desc`='{$desc}', `Date`='{$date}', Username='{$username}' WHERE Id={$id}";
		getQueryUpdate($query);
	}
	
	public static function deleteNews($id){
		$query = "DELETE FROM news WHERE Id={$id}";
		getQueryUpdate($query);
	}
}
?>